#include "syscall.h"

int reopen(int fid)
{
	Close(fid);
	fid = Open("myFile");
	if(fid == -1)
		Exit(2);
	return fid;
}


int main()
{
	int fid, numRead, i;
	char buffer[20];

	// Create and open a file
	Create("myFile");
	fid = Open("myFile");
	if(fid == -1)
		Exit(1);
	// Write some text to it
	Write("Text inside myfile\n", 20, fid);
	// Close and re-open it to reset the seek position
	fid = reopen(fid);
	// Read the written data and output to console
	numRead = Read(buffer, 20, fid);
	Write(buffer, numRead, ConsoleOutput);

	// Write over 100KB of data to the file to see that it expands
	for(i = 0; i < 102300; i++)
	{
		Write('a', 1, fid);
	}
}
